home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / osi / isode / dosisode / DOSISODE80.ZIP / ISODE8.WRK / UNIX / LIB / DNS / HERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-16  |  2.0 KB  |  65 lines

  1. #include <fiddle.h>
  2. /*
  3.  * Copyright (c) 1987 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted
  7.  * provided that: (1) source distributions retain this entire copyright
  8.  * notice and comment, and (2) distributions including binaries display
  9.  * the following acknowledgement:  ``This product includes software
  10.  * developed by the University of California, Berkeley and its contributors''
  11.  * in the documentation or other materials provided with the distribution
  12.  * and in all advertising materials mentioning features or use of this
  13.  * software. Neither the name of the University nor the names of its
  14.  * contributors may be used to endorse or promote products derived
  15.  * from this software without specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  17.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  18.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  */
  20.  
  21. #if defined(LIBC_SCCS) && !defined(lint)
  22. static char sccsid[] = "@(#)herror.c    6.5 (Berkeley) 6/1/90";
  23. #endif /* LIBC_SCCS and not lint */
  24.  
  25. #include <sys/types.h>
  26. #include <sys/uio.h>
  27.  
  28. char    *h_errlist[] = {
  29.     "Error 0",
  30.     "Unknown host",                /* 1 HOST_NOT_FOUND */
  31.     "Host name lookup failure",        /* 2 TRY_AGAIN */
  32.     "Unknown server error",            /* 3 NO_RECOVERY */
  33.     "No address associated with name",    /* 4 NO_ADDRESS */
  34. };
  35. int    h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
  36.  
  37. extern int    h_errno;
  38.  
  39. /*
  40.  * herror --
  41.  *    print the error indicated by the h_errno value.
  42.  */
  43. herror(s)
  44.     char *s;
  45. {
  46.     struct iovec iov[4];
  47.     register struct iovec *v = iov;
  48.  
  49.     if (s && *s) {
  50.         v->iov_base = s;
  51.         v->iov_len = strlen(s);
  52.         v++;
  53.         v->iov_base = ": ";
  54.         v->iov_len = 2;
  55.         v++;
  56.     }
  57.     v->iov_base = (u_int)h_errno < h_nerr ?
  58.         h_errlist[h_errno] : "Unknown error";
  59.     v->iov_len = strlen(v->iov_base);
  60.     v++;
  61.     v->iov_base = "\n";
  62.     v->iov_len = 1;
  63.     writev(2, iov, (v - iov) + 1);
  64. }
  65.